﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Threading;
using System.ComponentModel;
using System.Timers;
using System.Windows.Controls;
using System.Windows.Threading;


namespace app
{
    public class Clock : DispatcherObject// : INotifyPropertyChanged
    {
        private Timer m_Timer;
        //private DateTime m_DateTime;

        MainWindow mainWindow;
        
        public Clock(MainWindow window)
        {
            mainWindow = window;
            m_Timer = new Timer();
        }

        internal void StartClock()
        {
            m_Timer.Elapsed += new ElapsedEventHandler(ClockElapsed);
            m_Timer.Interval = 1000;
            m_Timer.Start();
        }

        private void ClockElapsed(object sender, ElapsedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {              
                mainWindow.ClockText.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            }), DispatcherPriority.Background);
        }
    }
}
